from rest_framework import serializers
from systems.models import Setting, SettingType,  Menu

# 序列化Setting模型
class SettingSerializer(serializers.ModelSerializer):
    status_display = serializers.CharField(
        source='get_status_display', read_only=True)
    type_display = serializers.CharField(
        source='get_type_display', read_only=True)
    class Meta:
        model = Setting
        fields = '__all__'

# 序列化SettingType模型
class SettingTypeSerializer(serializers.ModelSerializer):
    status_display = serializers.CharField(
        source='get_status_display', read_only=True)
    setting_name = serializers.CharField(source="setting", read_only=True)
    token = serializers.CharField(required=False, write_only=True)

    class Meta:
        model = SettingType
        fields = "__all__"

class MenuSerializer(serializers.ModelSerializer):
    roles = serializers.StringRelatedField(
        source="groups", many=True, read_only=True)

    class Meta:
        model = Menu
        fields = "__all__"
    